package uk.co.cngames.geekart;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class Browser extends Activity implements View.OnClickListener {

	WebView wvBrowser;
	Button 	btnBack; // TODO: Use back/forward or Previous/Next?
	Button 	btnForward;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		init();
	}

	private void init() {
		wvBrowser = (WebView) findViewById(R.id.webBrowser);
		btnBack = (Button) findViewById(R.id.btnBack);
		btnForward = (Button) findViewById(R.id.btnForward);

		wvBrowser.loadUrl("http://www.google.co.uk");
		wvBrowser.setWebViewClient(new WebViewClient());

		btnBack.setOnClickListener(this);
		btnForward.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		Intent i;

		switch (item.getItemId()) {
			case R.id.menu_settings:
				i = new Intent("uk.co.cngames.geekart.SETTINGS");
				startActivity(i);
			break;
			case R.id.menu_about:
				i = new Intent("uk.co.cngames.geekart.ABOUT");
				startActivity(i);
			break;
			case R.id.menu_exit:
				finish();
			break;
			case R.id.menu_browser:
				i = new Intent("uk.co.cngames.geekart.MAIN");
				startActivity(i);
			break;
		}
		return false;
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnBack:
			wvBrowser.goBack();
			break;
		case R.id.btnForward:
			wvBrowser.goForward();
			break;
		}
	}
}